package com.jzo2o.foundations.controller.consumer;

import com.jzo2o.foundations.model.dto.response.ServeAggregationSimpleResDTO;
import com.jzo2o.foundations.model.dto.response.ServeCategoryResDTO;
import com.jzo2o.foundations.model.dto.response.ServeSimpleResDTO;
import com.jzo2o.foundations.service.IHomeService;
import com.jzo2o.foundations.service.IServeAggregationService;
import com.jzo2o.foundations.service.IServeTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@RestController("consumerServeController")
@RequestMapping("/customer/serve")
@Api(tags = "用户端 - 首页服务查询接口")
public class FirstPageServeController {

    @Autowired
    private IHomeService homeService;

    @Autowired
    private IServeTypeService serveTypeService;

    @Autowired
    private IServeAggregationService serveAggregationService;

    @ApiOperation("首页服务列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "regionId", value = "区域ID", required = true, dataTypeClass = Long.class)
    })
    @GetMapping("/firstPageServeList")
    public List<ServeCategoryResDTO> serveCategory(@RequestParam("regionId") Long regionId) {
        return homeService.queryServeIconCategoryByRegionIdCache(regionId);
    }

    @ApiOperation("服务类型列表查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "regionId", value = "区域ID", required = true, dataTypeClass = Long.class)
    })
    @GetMapping("/serveTypeList")
    public List<HashMap<String, Object>> serveType(@RequestParam("regionId") Long regionId) {
        return serveTypeService.queryServeType(regionId);
    }

    @ApiOperation("首页热门服务列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "regionId", value = "区域ID", required = true, dataTypeClass = Long.class)
    })
    @GetMapping("/hotServeList")
    public List<ServeAggregationSimpleResDTO> hotServeList(@RequestParam("regionId") Long regionId) {
        return serveTypeService.hotServeList(regionId);
    }

    @ApiOperation("根据id查询服务")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务ID", required = true, dataTypeClass = Long.class)
    })
    @GetMapping("/{id}")
    public ServeAggregationSimpleResDTO getByServeId(@PathVariable("id") Long id) {
        return serveTypeService.getByServeId(id);
    }

    @ApiOperation("服务搜索接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cityCode", value = "城市编码", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(name = "keyword", value = "关键词", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "serveTypeId", value = "服务类型id", required = false, dataTypeClass = Long.class)
    })
    @GetMapping("/search")
    public List<ServeSimpleResDTO> search(String cityCode, String keyword, Long serveTypeId) {
        return serveAggregationService.findServeList(cityCode,keyword,serveTypeId);
    }
}